package struts.form;

import java.lang.reflect.Field;

import javax.servlet.http.HttpServletRequest;

public class FullForm {
	
	public FullForm(){
		
	}
	
	public static ActionForm full(String formpath,HttpServletRequest request) {
		ActionForm form = null;
		try {
			Class clazz = Class.forName(formpath);
			form = (ActionForm) clazz.newInstance();
			Field[] fileds = clazz.getDeclaredFields();
			for(Field field : fileds) {
				field.setAccessible(true);
				field.set(form, request.getParameter(field.getName()));
				field.setAccessible(false);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return form;
	}
	
	public static ActionForm full(Class clazz,HttpServletRequest request) {
		ActionForm form = null;
		try {
			form = (ActionForm) clazz.newInstance();
			Field[] fields = clazz.getDeclaredFields();
			for(Field field : fields) {
				field.setAccessible(true);
				field.set(form, request.getParameter(field.getName()));
				field.setAccessible(false);
			}
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return form;
	}

}
